package net.linku.repository;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.linku.domain.LAAccountRole;
import net.linku.enums.StatusEnum;
import net.linku.mapper.LAAccountRoleMapper;
import net.linku.model.req.menu.AdminRoleQuery;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class LAAccountRoleRepository extends ServiceImpl<LAAccountRoleMapper, LAAccountRole> {

    /**
     * 根据条件查询角色ID列表
     *
     * @param adminRoleQuery 包含查询条件的对象
     * @return 符合条件的角色ID列表
     */
    public List<LAAccountRole> queryRoleIdsByCondition(AdminRoleQuery adminRoleQuery) {
        // 创建查询条件包装器
        LambdaQueryWrapper<LAAccountRole> queryWrapper = new LambdaQueryWrapper<>();

        // 根据账户ID列表筛选
        if (adminRoleQuery.getAccountIds() != null && !adminRoleQuery.getAccountIds().isEmpty()) {
            queryWrapper.in(LAAccountRole::getAccountId, adminRoleQuery.getAccountIds());
        }

        // 根据租户ID筛选
        if (adminRoleQuery.getTenantId() != null) {
            queryWrapper.eq(LAAccountRole::getTenantId, adminRoleQuery.getTenantId());
        }

        // 筛选未删除的记录
        queryWrapper.eq(LAAccountRole::getDeletedFlag, StatusEnum.NORMAL.getDeletedFlag());

        // 执行查询并返回结果
        return this.list(queryWrapper);
    }
}
